<?php
//策略模式  做一个计算器

interface Math {
	public function calc($op1 ,$op2); 
}
	class MathAdd implements Math{
		public function calc($op1,$op2) {
			return $op1+$op2; 
		}
	}
	class MathSub implements Math{
		public function calc($op1,$op2) {
			return $op1-$op2 ; 
		}
	}
	class MathMul implements Math{
		public function calc($op1,$op2) {
			return $op1*$op2; 
		}
	}


/* 一般思路，根据传来0P ,制造不对对象,并且调用.
if($_ POST[ 'op']
*/

	class CMath {
		protected $calc = null ;
		public function  __construct($type){
			$calc = 'Math' . $type;
			$this->calc =new $calc();
		}
		public function calc($op1,$op2) {
			return $this->calc->calc($op1, $op2);
		}
	}

	//$type = $_POST['op'];	
	//$cmath = new CMath($type);
	//$cmath->calc($_POST['op1'],_POST['op2']);
	
	$type = 'add';
	$cmath = new CMath($type);
	echo $cmath->calc(3,5);

	
	
	
	
	
	
	
	
	
	
	